package com.zhike.api.controller.system;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhike.common.dto.R;
import com.zhike.common.dto.WebhookDTO;
import com.zhike.common.model.Webhook;
import com.zhike.common.vo.WebhookVO;
import com.zhike.service.system.IWebhookService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@RestController
@RequestMapping("/api/zkim/v1/")
@Api(tags = "webhook模块")
@Slf4j
public class WebhookController {

    @Autowired
    private IWebhookService webhookService;

    @ApiOperation(value = "webhook")
    @PostMapping("hook/{id}")
    public R hook(@PathVariable String id) {
        log.debug("webhook id {}", id);
        Webhook wh = webhookService.getWebhook(id);
        // TODO 向群里发消息
        return R.success();
    }

    @ApiOperation(value = "创建")
    @PostMapping("create")
    public R<WebhookVO> create(@RequestBody WebhookDTO dto) {
        return R.success(webhookService.create(dto));
    }
}
